﻿//===============================================================================
//	MessageFactory.h
//	消息工厂
//	接收和发送消息的处理
//===============================================================================

#pragma once

#include <unordered_map>
#include <cstdint>

class BaseMessage;

class MessageFactory
{
	typedef BaseMessage*(*CreateCallback)(uint32_t, uint32_t);

private:
	typedef std::unordered_map<uint32_t, CreateCallback> CallbackMap;
	CallbackMap m_callback_map;

public:
	MessageFactory();
	~MessageFactory();

public:
	void DeleteMessage(BaseMessage* val);
	BaseMessage* CreateMessage(uint32_t uid, uint32_t pn);

private:
	void registerMessage(uint32_t pn, CreateCallback cb);
	void unregisterMessage(uint32_t pn);

	void initialize(void);
};

